<template>
  <!--租户管理 -->
  <div>
    <upper-template
      @search="(searchForm.page = 1), searchFunc()"
      @clear="
        (searchForm.tenantName = ''),
          (searchForm.tenantId = ''),
          (searchForm.moduleCode = '')
      "
    >
      <div slot="buttonArea">
        <el-button @click="addFunc">新增</el-button>
        <el-button @click="editFunc">编辑</el-button>
        <el-button @click="delFunc">删除</el-button>
        <el-button @click="configEnList">工程配置</el-button>
      </div>
      <div slot="searchArea">
        <el-form
          ref="searchForm"
          :model="searchForm"
          label-width="87px"
          label-position="left"
          size="mini"
        >
          <el-form-item label="租户名称：">
            <el-input v-model="searchForm.tenantName" style="width: 150px" />
          </el-form-item>
          <el-form-item label="租户编号：">
            <el-input v-model="searchForm.tenantId" style="width: 150px" />
          </el-form-item>
          <el-form-item label="包含模块：" prop="moduleCodes">
            <el-select
              v-model="searchForm.moduleCode"
              style="width: 150px"
              placeholder="请选择"
            >
              <el-option
                v-for="item in moduleList"
                :key="item.moduleCode"
                :label="item.moduleName"
                :value="item.moduleCode"
              />
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div slot="columnHide">
        <el-checkbox-group v-model="checkList">
          <el-checkbox
            v-for="item in textData"
            :key="item.prop"
            :label="item.label"
            >{{ item.label }}
          </el-checkbox>
        </el-checkbox-group>
      </div>
    </upper-template>
    <el-table
      ref="multipleTable"
      :data="tableData"
      style="width: 100%"
      @row-click="rowClick"
    >
      <el-table-column width="55" type="selection" />
      <el-table-column
        v-if="tablePick[0]"
        prop="tenantId"
        label="租户编号"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="tablePick[1]"
        prop="tenantName"
        label="租户名称"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="tablePick[2]"
        prop="modules"
        label="包含模块"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{
            scope.row.modules
              .map((v) => {
                return v.moduleName;
              })
              .toString()
          }}
        </template>
      </el-table-column>

      <el-table-column
        v-if="tablePick[3]"
        prop="dataSourceConfigDTO.url"
        label="数据源信息"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="tablePick[4]"
        prop="modifier"
        label="修改人"
        sortable
        :formatter="(row) => row.modifier || '-'"
      />
      <el-table-column
        v-if="tablePick[5]"
        prop="modifiedTm"
        label="修改时间"
        sortable
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <div v-if="scope.row.modifiedTm">
            {{ timeFormat(scope.row.modifiedTm) }}
          </div>
          <div v-else>-</div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :current-page="searchForm.page"
      :page-size="searchForm.size"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      @refresh="searchFunc"
    />

    <!-- 新增和编辑弹窗 -->
    <el-dialog
      v-dialogDrag
      :title="saveTitles[saveFlg - 1]"
      :visible.sync="addOrEdit"
      width="40%"
    >
      <el-tabs v-model="activeName">
        <el-tab-pane label="基本信息" name="basicInfo">
          <el-form
            ref="saveForm"
            :model="saveForm"
            label-width="100px"
            label-position="left"
            :rules="saveFormRules"
            @submit.prevent="false"
          >
            <!-- v-if="saveFlg === 2" -->
            <el-form-item label="租户编码：" prop="tenantId">
              <el-input disabled v-model="saveForm.tenantId" maxlength="40" />
            </el-form-item>
            <el-form-item label="租户名称：" prop="tenantName">
              <el-input
                v-model="saveForm.tenantName"
                maxlength="40"
                :disabled="saveFlg === 2"
              />
            </el-form-item>
            <el-form-item label="包含模块：" prop="moduleCodes">
              <el-select
                multiple
                v-model="saveForm.moduleCodes"
                style="width: 100%"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in moduleList"
                  :key="item.moduleCode"
                  :label="item.moduleName"
                  :value="item.moduleCode"
                />
              </el-select>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="数据源信息" name="dataOriginInfo">
          <el-form
            ref="saveForm_data"
            :model="saveForm_data"
            label-width="auto"
            label-position="right"
            size="mini"
            :rules="saveForm_dataRules"
          >
            <h2 style="height: 20px; font-size: 14px">
              <span class="vertical-bar" /> 基础参数
            </h2>

            <el-form-item label="数据源名称：" required>
              <el-col :span="saveFlg == 2 ? 24 : 24">
                <el-form-item prop="dataSourceNameLast">
                  <el-input
                    style="width: 100%"
                    v-model.trim="saveForm_data.dataSourceNameLast"
                    :maxlength="
                      saveFlg == 1 ? 30 - saveForm.tenantId.length : 30
                    "
                    :disabled="saveFlg == 2"
                  >
                    <template slot="prepend" v-if="saveFlg == 1">
                      {{ saveForm.tenantId + "_" }}
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-form-item>
            <el-row>
              <el-col :span="24">
                <el-form-item label="数据库类型：" prop="datasourceType">
                  <el-select
                    v-model="saveForm_data.datasourceType"
                    placeholder="请选择"
                    style="width: 100%"
                    @change="changeDatasourceType"
                  >
                    <el-option
                      v-for="item in dataSourceTypeList"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>

            <el-form-item label="数据源url：" prop="url">
              <!-- maxlength="400"
                show-word-limit -->
              <el-input
                v-model.trim="saveForm_data.url"
                maxlength="400"
                type="textarea"
                :rows="2"
              >
              </el-input>
            </el-form-item>
            <el-form-item label="用户：" prop="username">
              <el-input v-model.trim="saveForm_data.username" />
            </el-form-item>
            <el-form-item label="密码：" prop="password">
              <el-input
                v-model.trim="saveForm_data.password"
                type="password"
                @focus="passwordClick"
              />
            </el-form-item>

            <h2 style="height: 20px; font-size: 14px">
              <span class="vertical-bar" /> 其他参数
            </h2>
            <el-col :span="12">
              <el-form-item label="初始线程数：" prop="initialSize">
                <el-input v-model="saveForm_data.initialSize" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="最大线程数：" prop="maxActive">
                <el-input v-model="saveForm_data.maxActive" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="最小空闲数：" prop="minIdle">
                <el-input v-model="saveForm_data.minIdle" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="最大空闲数：" prop="maxIdle">
                <el-input v-model="saveForm_data.maxIdle" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="最大等待时间：" prop="maxWait">
                <el-input v-model="saveForm_data.maxWait" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="重新检测时间："
                prop="timeBetweenEvictionRunsMillis"
              >
                <el-input
                  v-model="saveForm_data.timeBetweenEvictionRunsMillis"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="最小生存时间："
                prop="minEvictableIdleTimeMillis"
              >
                <el-input v-model="saveForm_data.minEvictableIdleTimeMillis" />
              </el-form-item>
            </el-col>
            <el-col :span="1"> </el-col>
            <el-col :span="10">
              <el-button @click="saveFunc_test">连接测试</el-button>
            </el-col>
          </el-form>
        </el-tab-pane>
      </el-tabs>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="saveFunc">确 定</el-button>
        <el-button @click="addOrEdit = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 新增和编辑弹窗 -->
    <el-dialog
      v-dialogDrag
      :title="saveProjectTitles[saveFlg - 1]"
      :visible.sync="addOrEditProject"
      width="500px"
    >
      <el-form
        ref="saveProjectForm"
        :model="saveProjectForm"
        label-width="77px"
        label-position="left"
        :rules="saveProjectFormRules"
        @submit.prevent="false"
      >
        <el-form-item label="工程名：" prop="projectName">
          <el-input v-model="saveProjectForm.projectName" maxlength="40" />
        </el-form-item>
        <el-form-item label="备注：" prop="remark">
          <el-input
            v-model="saveProjectForm.remark"
            type="textarea"
            maxlength="255"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="saveProjectFunc">确 定</el-button>
        <el-button @click="addOrEditProject = false">取 消</el-button>
      </div>
    </el-dialog>
    <!--工程列表弹窗  -->
    <el-dialog
      v-dialogDrag
      title="工程列表"
      width="800px"
      :visible.sync="enDialogEn"
      append-to-body
    >
      <el-row class="container">
        <upper-template
          :config-icon="false"
          @search="(searchProjectForm.page = 1), searchProjectFunc()"
          @clear="
            (searchProjectForm.projectId = ''),
              (searchProjectForm.projectName = '')
          "
        >
          <div slot="buttonArea">
            <el-button @click="addProjectFunc">新增</el-button>
            <el-button @click="editProjectFunc">编辑</el-button>
            <el-button @click="delProjectFunc">删除</el-button>
          </div>
          <div slot="searchArea">
            <el-form
              ref="searchForm"
              :model="searchProjectForm"
              label-width="87px"
              label-position="left"
              size="mini"
            >
              <el-form-item label="工程名称：">
                <el-input v-model="searchProjectForm.projectName" />
              </el-form-item>
              <el-form-item label="工程编号：">
                <el-input v-model="searchProjectForm.projectId" />
              </el-form-item>
            </el-form>
          </div>
        </upper-template>
        <el-table
          ref="multipleProjectTable"
          :data="projectTableData"
          style="width: 100%"
          @row-click="rowClickProject"
        >
          <el-table-column width="55" type="selection" />
          <el-table-column
            v-if="tablePick[0]"
            show-overflow-tooltip
            prop="projectId"
            label="工程编号"
          />
          <el-table-column
            v-if="tablePick[1]"
            show-overflow-tooltip
            prop="projectName"
            label="工程名称"
            align="center"
            sortable
          />
          <el-table-column
            v-if="tablePick[2]"
            show-overflow-tooltip
            prop="remark"
            label="备注"
            sortable
          />
        </el-table>
        <pagination
          :current-page="searchProjectForm.page"
          :page-size="searchProjectForm.size"
          :total="totalProject"
          @size-change="handleSizeChangeProject"
          @current-change="handleCurrentChangeProject"
          @refresh="searchProjectFunc"
        />
      </el-row>
      <div slot="footer">
        <el-button @click="enDialogEn = false">关闭</el-button>
      </div>
    </el-dialog>
    <!--工程列表弹窗 -->
  </div>
</template>

<script>
import sm4 from "@/lib/gmsm4/index";
import moment from "moment";
import { systemManage } from "@/api/index";
import userTable from "./userManage";
export default {
  components: {
    userTable,
  },
  data() {
    return {
      editFlag: 1,
      key: '00000000000000000000000000000000',
      projectTableData: [],
      addOrEditProject: false,
      dataSourceTypeList: [],
      moduleList: [],
      usersDialogEn: false,
      enDialogEn: false,
      addOrEdit: false,
      activeName: "basicInfo",
      projectDialog: false,
      usersDialog: false,
      currentRow: null,
      userRowEn: null,
      checkList: [
        "租户编号",
        "租户名称",
        "包含模块",
        "数据源信息",
        "修改人",
        "修改时间",
      ],
      tableData: [],
      textData: [
        { prop: "tenantCode", label: "租户编号" },
        { prop: "tenantName", label: "租户名称" },
        { prop: "moduleCodes", label: "包含模块" },
        { prop: "dataOrigin", label: "数据源信息" },
        { prop: "modifier", label: "修改人" },
        { prop: "modifiedTm", label: "修改时间" },
      ],
      saveFlg: false,
      saveTitles: ["新增租户", "修改租户"],
      saveProjectTitles: ["新增工程", "修改工程"],
      searchForm: {
        page: 1,
        size: 15,
        tenantName: "",
        tenantId: "",
        moduleCode: "",
      },
      searchProjectForm: {
        projectName: "",
        projectId: "",
        tenantId: "",
        page: 1,
        size: 15,
      },
      total: 0,
      totalProject: 0,
      saveForm: {
        moduleCodes: [],
        tenantId: "",
        tenantName: "",
      },
      saveForm_data: {
        dataSourceId: "",
        dataSourceName: "",
        datasourceType: "",
        initialSize: "",
        maxActive: "",
        maxIdle: "",
        maxWait: "",
        minEvictableIdleTimeMillis: "",
        minIdle: "",
        password: "",
        timeBetweenEvictionRunsMillis: "",
        url: "",
        username: "",
        dataSourceNameLast: "",
      },
      saveProjectForm: {
        projectId: "",
        projectName: "",
        remark: "",
      },
      saveFormRules: {
        tenantName: [
          { required: true, message: "请输入租户名称", trigger: "blur" },
          {
            pattern: /^[\u4E00-\u9FA5A-Za-z0-9]{1,40}$/,
            message: "只能输入1-40位中文、字母、数字或下划线",
            trigger: "blur",
          },
          // { validator: this.tenantNameValid, trigger: "blur" },
        ],
        tenantId: [
          { required: true, message: "请获取租户编码", trigger: "blur" },
        ],
        moduleCodes: [
          { required: true, message: "请选择模块", trigger: "blur" },
        ],
      },
      saveForm_dataRules: {
        dataSourceNameLast: [
          { required: true, message: "请输入数据源名称", trigger: "blur" },
            {
            pattern: /^[A-Za-z0-9]{1,}$/,
            message: "只能输入字母、数字或下划线",
            trigger: "blur",
          },
        ],
        moduleCodes: [
          { required: true, message: "请选择模块", trigger: "blur" },
        ],
        url: [{ required: true, message: "请输入数据源url", trigger: "blur" }],
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        datasourceType: [
          { required: true, message: "请选择数据库类型", trigger: "blur" },
        ],
        initialSize: [
          { pattern: /^[0-9]+$/, message: "只能输入数字", trigger: "blur" },
        ],
        maxActive: [
          { pattern: /^[0-9]+$/, message: "只能输入数字", trigger: "blur" },
        ],
        maxIdle: [
          { pattern: /^[0-9]+$/, message: "只能输入数字", trigger: "blur" },
        ],
        minIdle: [
          { pattern: /^[0-9]+$/, message: "只能输入数字", trigger: "blur" },
        ],
        maxWait: [
          { pattern: /^[0-9]+$/, message: "只能输入数字", trigger: "blur" },
        ],
        minEvictableIdleTimeMillis: [
          { pattern: /^[0-9]+$/, message: "只能输入数字", trigger: "blur" },
        ],
        timeBetweenEvictionRunsMillis: [
          { pattern: /^[0-9]+$/, message: "只能输入数字", trigger: "blur" },
        ],
      },
      saveProjectFormRules: {
        projectName: [
          { required: true, message: "该输入项为必输项", trigger: "blur" },
          {
            pattern: /^[\u4E00-\u9FA5A-Za-z0-9]{1,40}$/,
            message: "只能输入1-40位中文、字母、数字或下划线",
            trigger: "blur",
          },
        ],
      },
      enDataEn: [],
    };
  },
  computed: {
    tablePick() {
      return this.$tableDataPick(this.checkList, this.textData);
    },
  },
  watch: {
    addOrEdit() {
      this.activeName = "basicInfo";
      this.$nextTick(() => {
        if (this.$refs["saveForm"]) {
          this.$refs["saveForm"].clearValidate();
        }
        if (this.$refs["saveForm_data"]) {
          this.$refs["saveForm_data"].clearValidate();
        }
      });
    },
  },
  created() {
    this.queryInitData();
    this.$nextTick(() => {
      this.searchFunc();
    });
  },
  methods: {
    // 获取数据源url地址前缀
    changeDatasourceType(val) {
      let data = {
        dataSourceType: val,
      };
      systemManage.getDataSourceURL(data).then((res) => {
        if (res.code == 200) {
          this.saveForm_data.url = res.data;
          this.$forceUpdate();
        } else {
          this.$message.error(res.message || "获取默认数据源地址前缀失败");
        }
      });
    },
    passwordClick() {
      if (this.saveFlg == 2) {
        if (this.editFlag == 0) {
          this.editFlag = 1;
          this.saveForm_data.password = "";
        }
      }
    },
    timeFormat(val) {
      if (val) return moment(val).format("YYYY-MM-DD HH:mm:ss");
      else return "";
    },
    tenantNameValid(rule, val, callback) {
      // 只在新增时校验
      if (this.saveFlg != 1) {
        callback();
        return;
      }
      const data = {
        tenantId: this.saveForm.tenantId,
        tenantName: val,
      };
      systemManage.checkTenantName(data).then((res) => {
        if (res.code == 200) {
          callback();
        } else {
          callback(new Error("名称已存在"));
        }
      });
    },
    queryInitData() {
      // 查询初始化数据，字典下拉框等
      systemManage.queryAllEnableModules().then((res) => {
        if (res.code == 200) {
          this.moduleList = res.datas;
        }
      });
      // 数据库驱动集合
      this.$getDict("DATASOURCE_TYPE").then((res) => {
        if (res.code == 200) {
          this.dataSourceTypeList = res.datas;
        }
      });
    },
    searchClick() {
      this.searchForm.page = 1;
      this.searchFunc();
    },
    searchFunc() {
      const data = this.searchForm;
      systemManage.tenantQueryForPage(data).then((res) => {
        if (res.code == 200) {
          this.tableData = res.datas.rows;
          this.total = res.datas.total;
        }
      });
    },
    clearFunc() {
      for (const key in this.searchForm) {
        this.searchForm[key] = "";
      }
      this.searchForm.page = 1;
      this.searchForm.size = 15;
    },
    rowClick(row) {
      if (this.$refs.multipleTable) {
        this.$refs.multipleTable.clearSelection();
      }
      this.$refs.multipleTable.toggleRowSelection(row, true);
    },
    rowClickProject(row) {
      if (this.$refs.multipleProjectTable) {
        this.$refs.multipleProjectTable.clearSelection();
      }
      this.$refs.multipleProjectTable.toggleRowSelection(row, true);
    },
    getTenantIdCode() {
      let data = {
        id: "TENANT",
      };
      systemManage.generateIdentifier(data).then((res) => {
        if (res.code == 200) {
          this.saveForm.tenantId = res.data;
        } else {
          this.$message.error(res.message || "获取编码失败");
        }
      });
    },
    addFunc() {
      this.saveFlg = 1;
      for (const k in this.saveForm) {
        this.saveForm[k] = "";
      }
      this.saveForm.moduleCodes = [];
      for (const k in this.saveForm_data) {
        this.saveForm_data[k] = "";
      }
      // 获取自动生成的编码
      this.getTenantIdCode();
      this.addOrEdit = true;
    },
    editFunc() {
      this.editFlag = 0;
      this.saveFlg = 2;
      const selection = this.$refs.multipleTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条数据进行修改");
      }
      const row = selection[0];
      this.saveForm.tenantId = row.tenantId;
      this.saveForm.tenantName = row.tenantName;
      this.saveForm.moduleCodes = row.modules.map((v) => {
        return v.moduleCode;
      });
      // 获取数据源回显数据
      this.getDataSources(selection);
      this.addOrEdit = true;
    },
    getDataSources(selection) {
      let data = {
        id: selection[0].tenantId,
      };
      systemManage.getDataSources(data).then((res) => {
        if (res.code == 200) {
          this.saveForm_data = Object.assign({}, this.saveForm_data, res.data);
          this.saveForm_data.dataSourceNameLast = this.saveForm_data.dataSourceName;
          this.saveForm_data.password = "password";
        } else {
          this.$message.error(res.message || "获取数据源数据失败");
        }
      });
    },
    saveFunc() {
      this.$refs["saveForm"].validate((valid) => {
        if (valid) {
          this.$refs["saveForm_data"].validate((valid) => {
            if (valid) {
              this.saveFormFunc();
            } else {
              this.activeName = "dataOriginInfo";
            }
          });
        } else {
          this.activeName = "basicInfo";
        }
      });
    },
    saveFormFunc() {
      let data = {
        ...this.saveForm,
      };
      data = Object.assign({},data,this.saveForm_data)
      if (data.password != "password") {
        data.password = sm4.encryptWithECB(this.key, data.password);
      }
      // 新增
      if (this.saveFlg == 1) {
        data.dataSourceName =
          this.saveForm.tenantId + "" + this.saveForm_data.dataSourceNameLast;
      } else {
        data.dataSourceName = this.saveForm_data.dataSourceNameLast;
      }
      data.tenantId = this.saveForm.tenantId;
      systemManage.tenantSave(data).then((res) => {
        if (res.code == 200) {
          this.$message.success("保存成功");
          this.addOrEdit = false;
          this.searchFunc();
        } else {
          this.$message.error(res.message || "保存失败");
        }
      });
    },
    saveFunc_test() {
      this.$refs["saveForm_data"].validate((valid) => {
        if (valid) {
          let data = {
            ...this.saveForm_data,
          };
          if (data.password != "password") {
            data.password = sm4.encryptWithECB(this.key, data.password);
          }
          data.dataSourceName = this.saveForm_data.dataSourceNameLast;
          systemManage.dataSrcTestDs(data).then((res) => {
            if (res.code == 200 && res.success == true) {
              this.$message.success("连接成功");
            } else {
              this.$message.error(res.message || "连接失败,请检查输入信息");
            }
          });
        }
      });
    },
    searchProjectFunc() {
      const data = this.searchProjectForm;
      data.tenantId = this.userRowEn.tenantId;
      systemManage.queryProjectByTenant(data).then((res) => {
        this.projectTableData = res.data;
        this.totalProject = res.count;
      });
    },
    addProjectFunc() {
      this.saveFlg = 1;
      for (const k in this.saveProjectForm) {
        this.saveProjectForm[k] = "";
      }
      this.addOrEditProject = true;
    },
    editProjectFunc() {
      this.saveFlg = 2;
      const selection = this.$refs.multipleProjectTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条数据进行编辑");
      }
      const row = selection[0];
      const form = { ...row };
      this.saveProjectForm = form;
      this.addOrEditProject = true;
    },
    saveProjectFunc() {
      this.$refs["saveProjectForm"].validate((valid) => {
        if (valid) {
          const data = {
            ...this.saveProjectForm,
          };
          data.tenantId = this.userRowEn.tenantId;
          systemManage.projectSave(data).then((res) => {
            if (res.code == 200) {
              this.$message.success("保存成功");
              this.addOrEditProject = false;
              this.searchProjectFunc();
            } else {
              this.$message.error(res.message || "保存失败");
            }
          });
        }
      });
    },
    delProjectFunc() {
      const selection = this.$refs.multipleProjectTable.selection;
      if (selection.length < 1) {
        return this.$message.warning("请选择要删除的数据");
      }
      this.$confirm("您确定要删除选中数据吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let data = { proId: selection.map((v) => v.projectId) };
          data.tenantId = this.userRowEn.tenantId;
          systemManage.projectRemove(data).then((res) => {
            if (res.code == 200 && res.success == true) {
              this.$message.success("删除成功");
              this.searchProjectFunc();
            } else {
              this.$message.error(res.message || "删除失败");
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    delFunc() {
      const selection = this.$refs.multipleTable.selection;
      if (selection.length < 1) {
        return this.$message.warning("请选择要删除的数据");
      }
      this.$confirm("您确定要删除选中数据吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          const data = { ids: selection.map((v) => v.tenantId) };
          systemManage.tenantRemove(data).then((res) => {
            if (res.code == 200) {
              this.$message.success("删除成功");
              this.searchFunc();
            } else {
              this.$message.error(res.message || "删除失败");
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 配置工程打开工程弹窗
    configEnList() {
      const selection = this.$refs.multipleTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条数据");
      }
      this.userRowEn = selection[0];
      this.enDialogEn = true;
      console.log(selection, "selection566");
      // 查询该租户下的工程
      const data = {
        tenantId: selection[0].tenantId,
      };
      systemManage.queryProjectByTenant(data).then((res) => {
        if (res.code == 200) {
          this.projectTableData = res.data;
          this.totalProject = res.count;
        }
      });
    },
    handleSizeChange(val) {
      this.searchForm.size = val;
      this.searchFunc();
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.searchForm.page = val;
      this.searchFunc();
      console.log(`当前页: ${val}`);
    },
    handleSizeChangeProject(val) {
      this.searchProjectForm.size = val;
      this.searchProjectFunc();
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChangeProject(val) {
      this.searchProjectForm.page = val;
      this.searchProjectFunc();
      console.log(`当前页: ${val}`);
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
